import { createStore } from 'vuex'
import { applyList } from '@/server/friend'

import { getHomeFirendList, getGroupList } from '@/server/home'

const pannersApi = {
  "-2": () => { },
  "-1": () => { },
  "0": (data) => getGroupList(data),
  // "0": () => { },
  "1": () => { },
  "2": () => { },
  "3": (data) => getHomeFirendList(data)
  // "3": () => { }
}

export default createStore({
  state: {
    userInfo: {},
    applyData: {
      friendApply: [],
      groupApply: []
    },
    activePanners: [
      { name: "群聊", icon: "/icons/qun.png", data: [], show: true },
      { name: "手机联系人", icon: "/icons/phoneLink.png", data: [], show: false },
      { name: "星标朋友", icon: "/icons/newFriend.png", data: [], show: false },
      { name: "我的朋友", icon: "/icons/myFriend.png", data: [], show: true },
    ],
    selectSession: {},//当前选中的对话窗口
    pageIndex: 1,
    visible: false,
    searchSelectItem: [],//弹框选中好友

    selectMessages: [],//选中的消息

    openChecked: false, // 转发底部弹框

    searchType: 2,// 搜索弹框的搜索模式 1 搜索  2 创建群聊  3 转发

  },
  mutations: {
    saveInfo (state, playload) {
      state.userInfo = playload
    },
    saveApplyData (state, playload) {
      state.applyData = playload
    },
    saveActivePannersData (state, playload) {
      Reflect.get(state.activePanners, playload.type).data = playload.data
    },
    saveSelectSession (state, playload) {
      state.selectSession = playload
    },
    savePageIndex (state, playload) {
      state.pageIndex = playload
    },
    saveDialogState (state, visible) {
      state.visible = visible
    },
    saveSearchSelectItem (state, playload) {
      state.searchSelectItem = playload
    },
    saveSelectMessages (state, playload) {
      state.selectMessages = playload
    },
    saveOpenChecked (state, playload) {
      state.openChecked = playload
    },
    saveSearchType (state, playload) {
      state.searchType = playload
    },
    saveSelectCardInfo (state, playload) {
      state.selectCardInfo = playload
    }
  },
  actions: {
    async checkApplyList ({ commit, state }, playload) {
      const res = await applyList()
      commit("saveApplyData", res)
    },
    async getFriendByType ({ commit }, { index }) {
      const res = await Reflect.get(pannersApi, index)()
      if (res) commit('saveActivePannersData', { data: res, type: index })
    }
  },
  modules: {
  }
})



